import {message} from 'antd';
import {formatMessage} from './intl';

export const newOrUpdateOrderValidator = data => {
    const requiredFields = [];
    if(!data || !data.code)
        requiredFields.push(
            formatMessage({
                id: 'validator.code',
                defaultMessage: '仲裁编号'
            })
        );
    if(!data || !data.brandId)
        requiredFields.push(
            formatMessage({
                id: 'validator.brandId',
                defaultMessage: '品牌'
            })
        );
    if(!data || !data.dutyUnitId)
        requiredFields.push(
            formatMessage({
                id: 'validator.dutyUnitId',
                defaultMessage: '原供应商'
            })
        );
    if(!data || !data.replacedDutyUnitId)
        requiredFields.push(
            formatMessage({
                id: 'validator.replacedDutyUnitId',
                defaultMessage: '替换供应商'
            })
        );
    if(!data || !data.shareRate)
        if(data.shareRate !== 0) {
            requiredFields.push(
                formatMessage({
                    id: 'validator.shareRate',
                    defaultMessage: '承担比例'
                })
            );
        }
    if(!data || !data.endDate)
        requiredFields.push(
            formatMessage({
                id: 'validator.endDate',
                defaultMessage: '有效截止日期'
            })
        );
    if(requiredFields.length > 0) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.requied',
            defaultMessage: '必填'
        })}`);
        return false;
    }
    return true;
};
export const UpdateOrderValidator = data => {
    const requiredFields = [];
    if(!data || !data.code)
        requiredFields.push(
            formatMessage({
                id: 'validator.code',
                defaultMessage: '仲裁编号'
            })
        );
    if(!data || !data.brandId)
        requiredFields.push(
            formatMessage({
                id: 'validator.brandId',
                defaultMessage: '品牌'
            })
        );
    if(!data || !data.shareRate)
        if(data.shareRate !== 0) {
            requiredFields.push(
                formatMessage({
                    id: 'validator.shareRate',
                    defaultMessage: '承担比例'
                })
            );
        }
        
    if(!data || !data.endDate)
        requiredFields.push(
            formatMessage({
                id: 'validator.endDate',
                defaultMessage: '有效截止日期'
            })
        );
    if(requiredFields.length > 0) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.requied',
            defaultMessage: '必填'
        })}`);
        return false;
    }
    return true;
};
